package com.zwh.controller;

import com.zwh.entity.RedisUser;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@AllArgsConstructor
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;


    @GetMapping("/redisTestSet")
    public void redisTestSet(@Valid RedisUser redisUser) {
        redisTemplate.opsForValue().set(redisUser.getId(),redisUser.getName());
    }

    @GetMapping("/redisTestGet")
    public String redisTestGet(@Valid RedisUser redisUser) {
        String value = redisTemplate.opsForValue().get(redisUser.getId());
        return value;
    }
}
